﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Library.DAO;
using Library.Entity;

namespace DesignLife.Admin
{
    public partial class PortpolioManager : System.Web.UI.Page
    {
        private Portpolios port;
        private PortpoliosDAO portdao;
        public PortpolioManager()
        {
            port = new Portpolios();
            portdao = new PortpoliosDAO();
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadDB();
                div_success.Visible = false;
                div_error.Visible = false;

            }
        }
        private void LoadDB()
        {
          PortpoliosDAO portdao = new PortpoliosDAO();
            IList<Portpolios> lstport = portdao.GetAll();
            CollectionPager1.DataSource = lstport;
            CollectionPager1.BindToControl = dtlports;
            dtlports.DataSource = CollectionPager1.DataSourcePaged;
            dtlports.DataBind();


        }
        protected void Edit_Port(object source, DataListCommandEventArgs e)
        {
            Label lblID = e.Item.FindControl("lblID") as Label;
            Response.Redirect("EditManager/PortEdit.aspx?portsId=" + lblID.Text);
           
         
        }

        protected void Delete_Port(object source, DataListCommandEventArgs e)
        {
            string id = dtlports.DataKeys[e.Item.ItemIndex].ToString();
            portdao.Deleted(Int32.Parse(id));
            dtlports.EditItemIndex = -1;
            LoadDB();
        }

        protected void btnsubmit_Click(object sender, EventArgs e)
        {
            try
            {
                port.PortName = txtname.Text;
                port.Link = txtlink.Text;
                port.Img = txtPath.Text;
                port.Status = false;
                portdao.Insert(port);
                lblSuccess.Text = "add sucess";
                div_success.Visible = true;
                div_success.Visible = true;
                
                LoadDB();

            }
            catch (Exception ex)
            {

                throw ex;
            }
        }

        protected void btnsave_Click(object sender, EventArgs e)
        {
            HttpPostedFile file = Fuimage.PostedFile;

            try
            {
                string strPath = Server.MapPath("~/UploadFiles/" + Fuimage.FileName);
                Fuimage.SaveAs(strPath);
                txtPath.Text = "~/UploadFiles/" + Fuimage.FileName.ToString();
                lblSuccess.Text = "add success full";
                div_success.Visible = true;

            }
            catch (Exception ex)
            {

                lblError.Text = "Upload is not valida!";
                div_error.Visible = true;
            }
        }

    }
}